package cn.okcode.slowjson.ast;

import java.util.ArrayList;
import java.util.List;

/**
 * @author pyk13
 */
public class NodeContext {
    private final NodeContext parentContext;
    private final List<NodeContext> childContexts;

    /**
     * 对象深度，从0开始
     * 进入对象的属性或者数组元素的时候会增加
     */
    private final int scopeLevel;

    public int getScopeLevel() {
        return scopeLevel;
    }

    public NodeContext(NodeContext parentContext) {
        this.childContexts = new ArrayList<>();
        this.parentContext = parentContext;
        if (parentContext == null) {
            this.scopeLevel = 0;
        } else {
            this.scopeLevel = parentContext.scopeLevel + 1;
            parentContext.childContexts.add(this);
        }
    }
}
